import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class explosion here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class explosion extends Actor
{
    /** How many images should be used in the animation of the explostion */
    private final static int IMAGE_COUNT= 5;
    
    /** 
     * The images in the explosion. This is static so the images are not
     * recreated for every object (improves performance significantly).
     */
    private static GreenfootImage[] images;
    
    /** Current size of the explosion */
    private int imageNo = 0;
    
    /** How much do we increment the index in the explosion animation. */
    private int increment=0;
    
    /**
     * Create a new explosion.
     */
    public explosion() 
    {
        initializeImages();
        setImage(images[0]);
    }    
    
    /** 
     * Create the images for explosion.
     */
    public synchronized static void initializeImages() 
    {
        if(images == null) {
            images = new GreenfootImage[IMAGE_COUNT];
            for (int i = 0; i < IMAGE_COUNT; i++)
            {
                images[i] = new GreenfootImage("e" + (i+1) + ".png");
            }
        }
    }
    
    /**
     * Explode!
     */
    public void act()
    { 
        increment++;
        if(increment%3 == 0)
        {
            imageNo++;
        }
        if(imageNo < 5)
        {
            setImage(images[imageNo]);
        }
        else
        {
            getWorld().removeObject(this);
        }
    }
}
